/*
 * Negotiates P2P file transfer satifies Server role
 */
package rapidp2p.backend;

/**
 *
 * @author Rudy
 */
import java.io.*;
import java.net.*;


public class P2PServerClient {
    
    //private int port = 8008;
    private int port;//user is asked for desired client port
    private Socket listener;
    private boolean running = false;
    private Thread listenThread;
   
    //String currentDirectory =  System.getProperty("user.home");
    //private String shareDirectory = currentDirectory + "\\share\\";
    // File sharedFiles = new File(currentDirectory + "\\share\\");
   
   
   
  //  public String getShareDirectory(){
    
  //      return this.shareDirectory;
  //  }
    
    //public P2PServerClient(int port, String sharedDir){
    public P2PServerClient(int port){     
        this.port = port;
      //  this.shareDirectory = sharedDir;
    }
    
    public void begin(){
        UDPClient udpc = new UDPClient();
        udpc.uploadFileList();
        udpc.beginClient();
        System.out.println("CLOSED\n");
        //extract stuff from udpc's variables - savePath, hostIP
        //RequestFile rf = new RequestFile(File savePath, String hostIp);
    }

    
   public static void main (String [] args){
       String userInput = null;
       //TCPServer tcpserver = new TCPServer();
       //tcpserver.listenSocket();
       BufferedReader inFromUser =
         new BufferedReader(new InputStreamReader(System.in));
       try{
            System.out.println("Please enter desired port #, then ENTER\n");
            userInput = inFromUser.readLine();
            System.out.println(userInput);
       } catch (IOException io){
           System.out.println("BufferedReader problem\n");
           System.exit(-1);
       }
       
       P2PServerClient p2p = new P2PServerClient(Integer.parseInt(userInput));
       p2p.begin();
       //TCPServer tcpserver = new TCPServer();
       //TCPClient tcpclient = new TCPClient();
       
   }

            
  }
